﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using QuanLiThuVien.Source;
using QuanLiThuVien.LinkModel;

namespace QuanLiThuVien
{
    /// <summary>
    /// Interaction logic for DauSach.xaml
    /// </summary>
    public partial class DauSach : Window
    {
        private THUVIEN.Service1 serv = new THUVIEN.Service1();
        private InsertInfo m_insertInfo = new InsertInfo();
        public DauSach()
        {
            InitializeComponent();
            addCmbTheLoai(cmbTheLoai_DS);
        }

        private void addCmbTheLoai(ComboBox m_cmbTheLoai)
        {
            for (int i = 0; i < serv.ListTenTheLoai().Length; i++)
                m_cmbTheLoai.Items.Add(serv.ListTenTheLoai()[i]);            
        }

        private bool KiemTraNhap()
        {
            if (txtTenSach_DS.Text == "" || cmbTheLoai_DS.SelectedItem == null)
                return true;
            else return false;
        }

        private void bntOk_Click(object sender, RoutedEventArgs e)
        {
            if (KiemTraNhap())
                MessageBox.Show("Phải nhập đầy đủ thông tin trước khi đăng nhập", "Thông báo");
            else
            {
                string m_maTheLoai = serv.SelectMaTheLoai(cmbTheLoai_DS.SelectedItem.ToString()).ToString();
                m_insertInfo.InsertDauSach(txtTenSach_DS.Text, m_maTheLoai);
                this.Close();
            }
        }

        private void txtTenSach_DS_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
                bntOk_Click(sender, e);
        }

        private void bntHuy_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
